package com.atguigu.schedule.dao.impl;

import com.atguigu.schedule.dao.BaseDao;
import com.atguigu.schedule.dao.SysScheduleDao;
import com.atguigu.schedule.pojo.SysSchedule;

import java.util.List;

public class SysScheduleDapImpl extends BaseDao implements SysScheduleDao {
    @Override
    public int addSchedule(SysSchedule sysSchedule) {
        String sql = "insert into sys_schedule values(DEFAULT,?,?,?)";
        int rows = baseUpdate(sql, sysSchedule.getUid(), sysSchedule.getTitle(), sysSchedule.getCompleted());
        return rows;
    }

    @Override
    public List<SysSchedule> findAll() {
        String sql = "select * from sys_schedule";
        List<SysSchedule> list = baseQuery(SysSchedule.class, sql);
        return list;
    }

    @Override
    public List<SysSchedule> findItemListByUid(int uid) {
        String sql = "select * from sys_schedule where uid = ?";
        List<SysSchedule> list = baseQuery(SysSchedule.class, sql, uid);
        return list;
    }

    @Override
    public Integer addDefault(int uid) {
        String sql = "insert into  sys_schedule values (DEFAULT,?,'请输入日程',0)";
        return baseUpdate(sql, uid);
    }

    @Override
    public void updateSchedule(SysSchedule schedule) {
        String sql = "update sys_schedule set  title =?,completed=? where sid=?";
        baseUpdate(sql, schedule.getTitle(), schedule.getCompleted(), schedule.getSid());
    }

    @Override
    public void deleteSchedule(int sid) {
        String sql="delete from sys_schedule where sid=?";
        baseUpdate(sql, sid);
    }
}
